package com.hellpro.lolbox.video.model;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.video.bean.VideoClassifyBean;

import java.util.List;

/**
 * 类描述:
 * 创建人:阿犇
 * 创建时间:2016/10/19
 * 备注:
 */

public class ClassifyItemRecyclerViewAdapter extends BaseAdapter {

    private List<VideoClassifyBean.SubCategoryBean> mList;
    private int itemConunt;



    /*public interface OnSubRecyclerViewItemClickListener {
        void onItemClick(View view, int position);
    }

    private static OnSubRecyclerViewItemClickListener mListener;

    //设置条目的点击事件
    public void setOnSubRecyclerViewItemClickListener(OnSubRecyclerViewItemClickListener listener) {
        mListener = listener;
    }*/

    public ClassifyItemRecyclerViewAdapter() {
//        List<VideoClassifyBean.SubCategoryBean> list1 = new ArrayList<>();
//        if (subCategory.size() <= 8) {
//            list1.addAll(subCategory);
//        } else if (subCategory.size() > 8) {
//            list1.addAll(subCategory.subList(0, 8));
//        }

    }

    public void setData(List<VideoClassifyBean.SubCategoryBean> subCategory) {
        this.mList = subCategory;
    }


    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ItemViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.video_classify_sub_recycler_list_item, parent, false);
            holder = new ItemViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ItemViewHolder) convertView.getTag();
        }
        VideoClassifyBean.SubCategoryBean bean = mList.get(position);
        String dailyUpdate = bean.getDailyUpdate();
        //设置图片的最新视频数量
        if (!"0".equals(dailyUpdate)) {
            holder.llContent.setVisibility(View.VISIBLE);
            holder.itemTvCount.setText(bean.getDailyUpdate());
        }
        holder.itemIvShow.setImageURI(Uri.parse(bean.getIcon()));
        holder.itemTvName.setText(bean.getName());
        notifyDataSetChanged();

        return convertView;
    }

    /**
     * 类描述:
     * 创建人:阿犇
     * 创建时间:2016/10/19
     * 备注:填充布局
     */
   /* @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.video_classify_sub_recycler_list_item, parent, false);
        return new ItemViewHolder(view);
    }*/

    /**
     * 类描述:
     * 创建人:阿犇
     * 创建时间:2016/10/19
     * 备注:绑定数据
     */
   /* @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        if (position <= 7) {
            VideoClassifyBean.SubCategoryBean bean = mList.get(position);
            String dailyUpdate = bean.getDailyUpdate();
            //设置图片的最新视频数量
            if (!"0".equals(dailyUpdate)) {
                holder.llContent.setVisibility(View.VISIBLE);
                holder.itemTvCount.setText(bean.getDailyUpdate());
            }
            holder.itemIvShow.setImageURI(Uri.parse(bean.getIcon()));
            holder.itemTvName.setText(bean.getName());
        } else if (position > 7 && !mState) {
            VideoClassifyBean.SubCategoryBean bean = mList.get(position);
            String dailyUpdate = bean.getDailyUpdate();

            //设置图片的最新视频数量
            if (!"0".equals(dailyUpdate)) {
                holder.llContent.setVisibility(View.VISIBLE);
                holder.itemTvCount.setText(bean.getDailyUpdate());
            }
            holder.itemIvShow.setImageURI(Uri.parse(bean.getIcon()));
            holder.itemTvName.setText(bean.getName());

        }else if(position > 7&&mState){
            VideoClassifyBean.SubCategoryBean bean = mList.get(position);
            String dailyUpdate = bean.getDailyUpdate();

            //设置图片的最新视频数量
            if (!"0".equals(dailyUpdate)) {
                holder.llContent.setVisibility(View.VISIBLE);
                holder.itemTvCount.setText(bean.getDailyUpdate());
            }
            holder.itemIvShow.setImageURI(Uri.parse(bean.getIcon()));
            holder.itemTvName.setText(bean.getName());
        }
    }*/

    /**
     * 类描述:
     * 创建人:阿犇
     * 创建时间:2016/10/19
     * 备注:条目的数量
     */
    /*@Override
    public int getItemCount() {

        if (mList.size() <= 8) {
          return mList.size();
        } else if (mList.size() > 8 && !mState) {
           return 8;
        }else if(mList.size()> 8&&mState){
           return mList.size();
        }
        return 0;
    }*/

    class ItemViewHolder {

        private SimpleDraweeView itemIvShow;
        private LinearLayout llContent;
        private TextView itemTvCount;
        private TextView itemTvName;

        public ItemViewHolder(View convertView) {

            itemIvShow = (SimpleDraweeView) convertView.findViewById(R.id.video_item_recycler_ivShow);
            llContent = (LinearLayout) convertView.findViewById(R.id.video_item_recycler_llContent);
            itemTvCount = (TextView) convertView.findViewById(R.id.video_item_recycler_tvCount);
            itemTvName = (TextView) convertView.findViewById(R.id.video_item_recycler_tvName);
        }
    }
}
